package com.study.testSpringBoot.aspect;

import java.util.Arrays;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.study.testSpringBoot.testReflection.testReflection;

@Aspect
@Component
public class TestAspect {

	private Logger logger = LoggerFactory.getLogger(TestAspect.class);
	
	@Pointcut("execution(* com.study.testSpringBoot..*Service.*(..))")
	public void pointCut() {};
	
	@Before(value = "pointCut()")
	public void before(JoinPoint joinPoint) {
		logger.info("参数信息"+joinPoint.getArgs());
		Object[] args = joinPoint.getArgs();
		System.out.println(args[0]);
		System.out.println(args[1]);
		testReflection.verificationParam(args[0]);
		testReflection.verificationParam(args[1]);
		logger.info("方法名"+joinPoint.getSignature().getDeclaringTypeName());
		throw new RuntimeException("又来一下出错。。。");
	}
	
	/**
	 * 异常信息切面
	 * @param joinPoint
	 * @param exception
	 */
	@AfterThrowing(value="pointCut()",throwing="exception")
	public void logException(JoinPoint joinPoint,Exception exception){
		logger.error("异常方法:"+joinPoint.getSignature().getName()+"\n异常信息：{"+exception.getMessage()+"}");
	}
}
